here::i_am("replication_materials.Rproj")

library(tidyverse)

getwd()

df <- readRDS(file = "data.rds")

names(df)

# Descriptives ####

# Figure 1 (People Violine by Party Family) ####

df %>% 
  select(family_label, populism_mean, peopleimm, peoplewealthy) %>% 
  pivot_longer(cols = peopleimm:peoplewealthy, values_to = "score", names_to = "dimension") %>% 
  mutate(dimension = factor(dimension,
                            levels = c("peopleimm", "peoplewealthy"),
                            labels = c("Citizens with migration background", "Very wealthy citizens")),
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  ggplot(., aes(x = family_label,
                y = score
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the people \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/Figure1.png", width = 18, height = 12, units = "cm")

# Figure 2 (Elite Violine by Party Family) ####


df %>% 
  select(family_label, populism_mean, contains("elite")) %>% 
  pivot_longer(cols = elitepol:elitecult, values_to = "score", names_to = "dimension") %>% 
  mutate(dimension = factor(dimension,
                            levels = c("elitepol", "elitemedia", "eliteecon", "elitecult"),
                            labels = c("Politicans", "Journalists", "CEOs", "Academics")),
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  ggplot(., aes(x = family_label,
                y = score
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_wrap(~dimension, nrow = 2) +
  labs(x = "Party Families",
       y = "Belonging to the elite \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/Figure2.png", width = 18, height = 18, units = "cm")

# Figure C1 (Descriptive People by country) ####

df %>% 
  select(country_short, populism_mean, peopleimm, peoplewealthy) %>% 
  pivot_longer(cols = peopleimm:peoplewealthy, values_to = "score", names_to = "dimension") %>% 
  mutate(dimension = factor(dimension,
                            levels = c("peopleimm", "peoplewealthy"),
                            labels = c("Citizens with migration background", "Very wealthy citizens")),
         country_short = forcats::fct_rev(country_short)) %>% 
  ggplot(., aes(x = country_short,
                y = score
  )) +
  geom_point(alpha = 0.25) +
  coord_flip() +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 3) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Country",
       y = "Belonging to the people \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC1.png", width = 18, height = 12, units = "cm")

# Figure C2 (Descriptive Elite by country) ####

df %>% 
  select(country_short, populism_mean, contains("elite")) %>% 
  pivot_longer(cols = elitepol:elitecult, values_to = "score", names_to = "dimension") %>% 
  mutate(dimension = factor(dimension,
                            levels = c("elitepol", "elitemedia", "eliteecon", "elitecult"),
                            labels = c("Politicans", "Journalists", "CEOs", "Academics")),
         country_short = forcats::fct_rev(country_short)) %>% 
  ggplot(., aes(x = country_short,
                y = score
  )) +
  geom_point(alpha = 0.25) +
  coord_flip() +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 3) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_wrap(~dimension, nrow = 2) +
  labs(x = "Country",
       y = "Belonging to the elite \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC2.png", width = 18, height = 25, units = "cm")

# Figure C3 (violines with labels) for immigration ####

df %>% 
  select(party_short, family_label, populism_mean, peopleimm) %>% 
  mutate(dimension = "Citizens with migration background",
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  group_by(family_label) %>%
  mutate(
    lower_bound = quantile(peopleimm, 0.10, na.rm = TRUE),  
    upper_bound = quantile(peopleimm, 0.90, na.rm = TRUE)   
  ) %>%
  ungroup() %>% 
  ggplot(., aes(x = family_label,
                y = peopleimm
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  ggrepel::geom_text_repel(aes(label = ifelse(peopleimm < lower_bound | peopleimm > upper_bound, 
                                              party_short, 
                                              NA)),
                           size = 2, 
                           max.overlaps = 30,
                           show.legend = FALSE) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the people \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC3.png", width = 18, height = 12, units = "cm")

# Figure C4 (violines with labels) for wealthy citizens ####

df %>% 
  select(party_short, family_label, populism_mean, peoplewealthy) %>% 
  mutate(dimension = "Very wealthy citizens",
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  group_by(family_label) %>%
  mutate(
    lower_bound = quantile(peoplewealthy, 0.10, na.rm = TRUE),  
    upper_bound = quantile(peoplewealthy, 0.90, na.rm = TRUE)   
  ) %>%
  ungroup() %>% 
  ggplot(., aes(x = family_label,
                y = peoplewealthy
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  ggrepel::geom_text_repel(aes(label = ifelse(peoplewealthy < lower_bound | peoplewealthy > upper_bound, 
                                              party_short, 
                                              NA)),
                           size = 2, 
                           max.overlaps = 30,
                           show.legend = FALSE) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the people \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC4.png", width = 18, height = 12, units = "cm")

# Figure C5 (violines with labels) for politicans ####

df %>% 
  select(party_short, family_label, populism_mean, elitepol) %>% 
  mutate(dimension = "Politicians",
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  group_by(family_label) %>%
  mutate(
    lower_bound = quantile(elitepol, 0.10, na.rm = TRUE),  
    upper_bound = quantile(elitepol, 0.90, na.rm = TRUE)   
  ) %>%
  ungroup() %>% 
  ggplot(., aes(x = family_label,
                y = elitepol
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  ggrepel::geom_text_repel(aes(label = ifelse(elitepol < lower_bound | elitepol > upper_bound, 
                                              party_short, 
                                              NA)),
                           size = 2, 
                           max.overlaps = 30,
                           show.legend = FALSE) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the elite \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC5.png", width = 18, height = 12, units = "cm")

# Figure C6 (violines with labels) for journalists ####

df %>% 
  select(party_short, family_label, populism_mean, elitemedia) %>% 
  mutate(dimension = "Journalists",
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  group_by(family_label) %>%
  mutate(
    lower_bound = quantile(elitemedia, 0.10, na.rm = TRUE),  
    upper_bound = quantile(elitemedia, 0.90, na.rm = TRUE)   
  ) %>%
  ungroup() %>% 
  ggplot(., aes(x = family_label,
                y = elitemedia
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  ggrepel::geom_text_repel(aes(label = ifelse(elitemedia < lower_bound | elitemedia > upper_bound, 
                                              party_short, 
                                              NA)),
                           size = 2, 
                           max.overlaps = 30,
                           show.legend = FALSE) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the elite \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC6.png", width = 18, height = 12, units = "cm")

# Figure C7 (violines with labels) for CEOs ####

df %>% 
  select(party_short, family_label, populism_mean, eliteecon) %>% 
  mutate(dimension = "CEOs",
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  group_by(family_label) %>%
  mutate(
    lower_bound = quantile(eliteecon, 0.10, na.rm = TRUE),  
    upper_bound = quantile(eliteecon, 0.90, na.rm = TRUE)   
  ) %>%
  ungroup() %>% 
  ggplot(., aes(x = family_label,
                y = eliteecon
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  ggrepel::geom_text_repel(aes(label = ifelse(eliteecon < lower_bound | eliteecon > upper_bound, 
                                              party_short, 
                                              NA)),
                           size = 2, 
                           max.overlaps = 30,
                           show.legend = FALSE) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the elite \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC7.png", width = 18, height = 12, units = "cm")

# Figure C8 (violines with labels) for Academics ####

df %>% 
  select(party_short, family_label, populism_mean, elitecult) %>% 
  mutate(dimension = "Academics",
         family_label = forcats::fct_reorder(family_label, populism_mean, .na_rm = TRUE)) %>% 
  group_by(family_label) %>%
  mutate(
    lower_bound = quantile(elitecult, 0.10, na.rm = TRUE),  
    upper_bound = quantile(elitecult, 0.90, na.rm = TRUE)   
  ) %>%
  ungroup() %>% 
  ggplot(., aes(x = family_label,
                y = elitecult
  )) +
  geom_point(position = position_jitter(seed = 123,
                                        width = 0.2),
             alpha = 0.5) +
  ggrepel::geom_text_repel(aes(label = ifelse(elitecult < lower_bound | elitecult > upper_bound, 
                                              party_short, 
                                              NA)),
                           size = 2, 
                           max.overlaps = 30,
                           show.legend = FALSE) +
  coord_flip() +
  geom_violin(alpha = .0) +
  stat_summary(fun = "mean",
               geom = "point",
               color = "red", shape = 18, size = 2) +
  theme_minimal() +
  guides(color = "none") +
  scale_y_continuous(breaks = 0:10) +
  facet_grid(~dimension) +
  labs(x = "Party Families",
       y = "Belonging to the elite \n(0 = low, 10 = high)") +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureC8.png", width = 18, height = 12, units = "cm")

# Models: Main effects ####

m1_imm <- lm(peopleimm ~ populism_mean + lroverall + country, df)
m1_wel <- lm(peoplewealthy ~ populism_mean + lroverall + country, df)
m2_imm <- lm(peopleimm ~ populism_mean + lrecon + nativism + country, df)
m2_wel <- lm(peoplewealthy ~ populism_mean + lrecon + nativism + country, df)

m1_pol <- lm(elitepol ~ populism_mean + lroverall + country, df)
m1_med <- lm(elitemedia ~ populism_mean + lroverall + country, df)
m1_eco <- lm(eliteecon ~ populism_mean + lroverall + country, df)
m1_cul <- lm(elitecult ~ populism_mean + lroverall + country, df)
m2_pol <- lm(elitepol ~ populism_mean + lrecon + nativism + country, df)
m2_med <- lm(elitemedia ~ populism_mean + lrecon + nativism + country, df)
m2_eco <- lm(eliteecon ~ populism_mean + lrecon + nativism + country, df)
m2_cul <- lm(elitecult ~ populism_mean + lrecon + nativism + country, df)

texreg::screenreg(list(m1_imm, m2_imm, m1_wel, m2_wel),
                  custom.model.names = c("P: Immigrants", "P: Immigrants", "P: Wealthy", "P: Wealthy"),
                  omit.coef = "country")

texreg::screenreg(list(m1_pol, m2_pol, m1_med, m2_med, m1_eco, m2_eco, m1_cul, m2_cul),
                  custom.model.names = c("E: Politicians", "E: Politicians", "E: Media", "E: Media",
                                         "E: Econ", "E: Econ", "E: Cult", "E: Cult"),
                  omit.coef = "country")

# Table B1 ####

texreg::texreg(list(m1_imm, m1_wel),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_mean" = "Populism",
                                      "lroverall" = "Overall Left-Right Position",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableB1", 
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB1.tex")

# Table B2 ####

texreg::texreg(list(m2_imm, m2_wel),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_mean" = "Populism",
                                      "lrecon" = "Economic Left-Right Position",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               label = "tab:tableB2", 
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB2.tex")

# Table B3 ####

texreg::texreg(list(m1_pol, m1_med, m1_eco, m1_cul),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_mean" = "Populism",
                                      "lroverall" = "Overall Left-Right Position",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.9\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableB3",
               stars = c(0.1, 0.05, 0.01),
               scalebox = .8,
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB3.tex")

# Table B4 ####

texreg::texreg(list(m2_pol, m2_med, m2_eco, m2_cul),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_mean" = "Populism",
                                       "lrecon" = "Economic Left-Right",
                                       "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.9\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableB4",
               stars = c(0.1, 0.05, 0.01),
               scalebox = .8,
               dcolumn = T,
               use.packages = F,
                file = "./tables/TableB4.tex")

# Figure 3 (Coefficient Plots for Main models and people) ####

data.frame(iv = rep(c("populism_mean", "lroverall", "populism_mean", "lrecon", "nativism"),2),
           dv = rep(c("peopleimm", "peoplewealthy "), each = 5),
           dim = rep(c("1D","1D", "2D","2D","2D"), 2),
           coef = c(m1_imm$coefficients[c("populism_mean", "lroverall")],
                    m2_imm$coefficients[c("populism_mean", "lrecon", "nativism")],
                    m1_wel$coefficients[c("populism_mean", "lroverall")],
                    m2_wel$coefficients[c("populism_mean", "lrecon", "nativism")]),
           se = c(sqrt(diag(vcov((m1_imm))))[c("populism_mean", "lroverall")],
                  sqrt(diag(vcov((m2_imm))))[c("populism_mean", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_wel))))[c("populism_mean", "lroverall")],
                  sqrt(diag(vcov((m2_wel))))[c("populism_mean", "lrecon", "nativism")])) %>% 
  mutate(lower95 = coef - 1.96*se,
         upper95 = coef + 1.96*se,
         lower90 = coef - 1.645*se,
         upper90 = coef + 1.645*se,
         iv = forcats::fct_rev(factor(iv, 
                                     levels = c("populism_mean", "lroverall", "lrecon", "nativism"),
                                     labels = c("Populism", "Overall left-right", "Economic left-right", "Nativism"))),
         dim = factor(dim,
                      levels = c("1D", "2D"),
                      labels = c("One-Dimensional Model", "Two-Dimensional Model")),
         dv = factor(dv, 
                     levels = c("peopleimm", "peoplewealthy "),
                     labels = c("Citizens with migration background", "Very wealthy citizens"))) %>% 
  ggplot(., aes(x = iv, y = coef, ymin = lower95, ymax = upper95, colour = forcats::fct_rev(dim), shape = forcats::fct_rev(dim))) +
  geom_hline(yintercept = 0, lty ="dotted") +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = lower90, ymax = upper90), position = position_dodge(width = 1), linewidth = 0.75) +
  theme_minimal() +
  facet_grid(~dv) + 
  coord_flip(xlim = c(1, 4),  ylim=c(-0.8, 0.8), clip="off") +
  theme(legend.position = "bottom") +
  scale_colour_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  scale_shape_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  labs(x = "Predictor", y = "") +
  annotate("segment", 
           x = -0.45, xend = -0.45, y = -0.1, yend = -0.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.3, y = -0.3, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.45, xend = -0.45, y = 0.1, yend = 0.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.3, y = 0.3, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 0.0, 
           label = "Belong to the people",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/Figure3.png", width = 18, height = 9, units = "cm")

# Figure 5 (Coefficient Plots for Main models and elite) ####

data.frame(iv = rep(c("populism", "lroverall", "populism", "lrecon", "nativism"),2),
           dv = rep(c("elitepol", "elitemedia", "eliteecon", "elitecult"), each = 5),
           dim = rep(c("1D","1D", "2D","2D","2D"), 2),
           coef = c(m1_pol$coefficients[c("populism_mean", "lroverall")],
                    m2_pol$coefficients[c("populism_mean", "lrecon", "nativism")],
                    m1_med$coefficients[c("populism_mean", "lroverall")],
                    m2_med$coefficients[c("populism_mean", "lrecon", "nativism")],
                    m1_eco$coefficients[c("populism_mean", "lroverall")],
                    m2_eco$coefficients[c("populism_mean", "lrecon", "nativism")],
                    m1_cul$coefficients[c("populism_mean", "lroverall")],
                    m2_cul$coefficients[c("populism_mean", "lrecon", "nativism")]),
           se = c(sqrt(diag(vcov((m1_pol))))[c("populism_mean", "lroverall")],
                  sqrt(diag(vcov((m2_pol))))[c("populism_mean", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_med))))[c("populism_mean", "lroverall")],
                  sqrt(diag(vcov((m2_med))))[c("populism_mean", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_eco))))[c("populism_mean", "lroverall")],
                  sqrt(diag(vcov((m2_eco))))[c("populism_mean", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_cul))))[c("populism_mean", "lroverall")],
                  sqrt(diag(vcov((m2_cul))))[c("populism_mean", "lrecon", "nativism")])) %>% 
  mutate(lower95 = coef - 1.96*se,
         upper95 = coef + 1.96*se,
         lower90 = coef - 1.645*se,
         upper90 = coef + 1.645*se,
         iv = forcats::fct_rev(factor(iv, 
                                      levels = c("populism", "lroverall", "lrecon", "nativism"),
                                      labels = c("Populism", "Overall left-right", "Economic left-right", "Nativism"))),
         dim = factor(dim,
                      levels = c("1D", "2D"),
                      labels = c("One-Dimensional Model", "Two-Dimensional Model")),
         dv = factor(dv, 
                     levels = c("elitepol", "elitemedia", "eliteecon", "elitecult"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  ggplot(., aes(x = iv, y = coef, ymin = lower95, ymax = upper95, colour = forcats::fct_rev(dim), shape = forcats::fct_rev(dim))) +
  geom_hline(yintercept = 0, lty ="dotted") +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = lower90, ymax = upper90), position = position_dodge(width = 1), linewidth = .75) +
  theme_minimal() +
  facet_wrap(~dv, nrow = 2,axes = "all_x") + 
  coord_flip(xlim = c(1, 4),  ylim=c(-0.35, 0.35), clip="off") +
  theme(legend.position = "bottom") +
  scale_colour_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  scale_shape_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  labs(x = "Predictor", y = "") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = -0.1, yend = -0.3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = -0.15, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 0.1, yend = 0.3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 0.15, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 0.0, 
           label = "Belong to the elite",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines"))

ggsave("./figures/Figure5.png", width = 18, height = 18, units = "cm")

# Models: Interaction effects ####

df$lroverall3 <- ifelse(df$lroverall < 3, "Left",
                        ifelse(df$lroverall > 7, "Right",
                               ifelse(is.na(df$lroverall), NA, "Centre")))

df$nativism3 <- factor(ifelse(df$nativism < 3, "Low",
                              ifelse(df$lroverall > 7, "High",
                                     ifelse(is.na(df$lroverall), NA, "Medium"))),
                       levels = c("Low", "Medium", "High"))

df$lrecon3 <- factor(ifelse(df$lrecon < 3, "Left",
                            ifelse(df$lrecon > 7, "Right",
                                   ifelse(is.na(df$lrecon), NA, "Centre"))),
                     levels = c("Centre", "Left", "Right"))


table(df$lroverall3)
table(df$nativism3)
table(df$lrecon3)

m1_imm3 <- lm(peopleimm ~ populism_mean * lroverall3 + country, df)
m1_wel3 <- lm(peoplewealthy ~ populism_mean * lroverall3 + country, df)
m2_imm3 <- lm(peopleimm ~ populism_mean * (lrecon3 + nativism3) + country, df)
m2_wel3 <- lm(peoplewealthy ~ populism_mean * (lrecon3 + nativism3) + country, df)

m1_pol3 <- lm(elitepol ~ populism_mean * lroverall3 + country, df)
m1_med3 <- lm(elitemedia ~ populism_mean * lroverall3 + country, df)
m1_eco3 <- lm(eliteecon ~ populism_mean * lroverall3 + country, df)
m1_cul3 <- lm(elitecult ~ populism_mean * lroverall3 + country, df)
m2_pol3 <- lm(elitepol ~ populism_mean * (lrecon3 + nativism3) + country, df)
m2_med3 <- lm(elitemedia ~ populism_mean * (lrecon3 + nativism3) + country, df)
m2_eco3 <- lm(eliteecon ~ populism_mean * (lrecon3 + nativism3) + country, df)
m2_cul3 <- lm(elitecult ~ populism_mean * (lrecon3 + nativism3) + country, df)

# Table B5 ####

texreg::texreg(list(m1_imm3, m1_wel3),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_mean" = "Populism",
                                       "lroverall3Left" = "Left-wing party",
                                       "lroverall3Right" = "Right-wing party",
                                       "populism_mean:lroverall3Left" = "Populism x Left-wing",
                                       "populism_mean:lroverall3Right" = "Populism x Right-wing",
                                       "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism $\\times$ ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableB5",
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB5.tex")

# Table B6 ####

texreg::texreg(list(m2_imm3, m2_wel3),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_mean" = "Populism",
                                      "lrecon3Left" = "Economically left-wing party",
                                      "lrecon3Right" = "Economically right-wing party",
                                      "nativism3Medium" = "Medium Nativist",
                                      "nativism3High" = "Highly Nativist",
                                      "populism_mean:lrecon3Left" = "Populism x Economically left-wing",
                                      "populism_mean:lrecon3Right" = "Populism x Economically right-wing",
                                      "populism_mean:nativism3Medium" = "Populism x Medium nativist party",
                                      "populism_mean:nativism3High" = "Populism x Highly nativist party",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism $\\times$ ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableB6",
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB6.tex")


# Table B7 ####

texreg::texreg(list(m1_pol3, m1_med3, m1_eco3, m1_cul3),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_mean" = "Populism",
                                      "lroverall3Left" = "Left-wing Party",
                                      "lroverall3Right" = "Right-wing Party",
                                      "populism_mean:lroverall3Left" = "Populism x Left-Wing Party",
                                      "populism_mean:lroverall3Right" = "Populism x Right-Wing Party",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism $\\times$ ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "table:tableB7",
               scalebox = .7,
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB7.tex")

# Table B8 ####

texreg::texreg(list(m2_pol3, m2_med3, m2_eco3, m2_cul3),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_mean" = "Populism",
                                      "lrecon3Left" = "Economically left-wing party",
                                      "lrecon3Right" = "Economically right-wing party",
                                      "nativism3Medium" = "Medium Nativist",
                                      "nativism3High" = "Highly Nativist",
                                      "populism_mean:lrecon3Left" = "Populism x Economically left",
                                      "populism_mean:lrecon3Right" = "Populism x Economically right",
                                      "populism_mean:nativism3Medium" = "Populism x Medium nativist",
                                      "populism_mean:nativism3High" = "Populism x Highly nativist",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism $\\times$ ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "table:tableB8",
               scalebox = .7,
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableB8.tex")

# Figure 4 (Prediction of belonging to the people) ####

bind_rows(prediction::prediction(m1_imm3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lroverall = 2) %>% 
            mutate(dv = "Citizens with migration background"),
          prediction::prediction(m1_wel3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lroverall = 2) %>% 
            mutate(dv = "Very wealthy citizens")) %>% 
  mutate(populism_mean = factor(populism_mean,
                           levels = c(2,8),
                           labels = c("Low (2)", "High (8)"))) %>% 
  ggplot(., aes(x = lroverall, y = Prediction, ymin = lower, ymax = upper, colour = factor(populism_mean), shape = factor(populism_mean))) +
  geom_pointrange(position = position_dodge(width = 0.25), size = .25) +
  geom_linerange(aes(ymin = Prediction - 1.645 * SE, ymax = Prediction + 1.645 * SE), position = position_dodge(width = 0.25), size = .75) +
  theme_minimal() +
  facet_grid(~dv) + 
  coord_flip(xlim = c(1, 3),  ylim=c(0, 10), clip="off") +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Overall Left-Right Position", y = "") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 4, yend = 0.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 2.5, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 6, yend = 9.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 7.5, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 5.0, 
           label = "Belong to the people",
           size = 3, color = "black") +
  NULL

ggsave("./figures/Figure4.png", width = 18, height = 9, units = "cm")

# Figure D1 (Margins People LR Overall) ####

bind_rows(margins::margins(m1_imm3, variables = "populism_mean",
                           at = list(lroverall3 = c("Left", "Centre", "Right"))) %>%
            summary() %>% 
            data.frame() %>% 
            mutate(dv = "Citizens with migration background"),
          margins::margins(m1_wel3, variables = "populism_mean",
                           at = list(lroverall3 = c("Left", "Centre", "Right"))) %>%
            summary() %>%
            data.frame() %>% 
            mutate(dv = "Very wealthy citizens")) %>% 
  ggplot(., aes(x = lroverall3, y = AME, ymin = lower, ymax = upper)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_pointrange() +
  theme_minimal() +
  facet_grid(~dv) + 
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Overall Left-Right Position", y = "Marginal Effect of Populism\non belonging to the People") +
  annotate("segment", 
           x = 0.8, xend = 0.8, y = -.15, yend = -.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = 0.6, y = -.4, 
           label = "Belong to the people: less",
           size = 3, color = "black", angle = 90)

ggsave("./figures/FigureD1.png", width = 18, height = 9, units = "cm")

# Figure D2 (Prediction People with econ LR) ####

bind_rows(prediction::prediction(m2_imm3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lrecon = 2) %>% 
            mutate(dv = "Citizens with migration background"),
          prediction::prediction(m2_wel3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lrecon = 2) %>% 
            mutate(dv = "Very wealthy citizens")) %>% 
  mutate(populism_mean = factor(populism_mean,
                           levels = c(2,8),
                           labels = c("Low (2)", "High (8)")),
         lrecon = factor(lrecon,
                         levels = c("Left", "Centre", "Right"))) %>% 
  ggplot(., aes(x = lrecon, y = Prediction, ymin = lower, ymax = upper, colour = factor(populism_mean), shape = factor(populism_mean))) +
  geom_pointrange(position = position_dodge(width = 0.25), size = .25) +
  geom_linerange(aes(ymin = Prediction - 1.645 * SE, ymax = Prediction + 1.645 * SE), linewidth = 1, position = position_dodge(width = 0.25)) +
  theme_minimal() +
  facet_grid(~dv) +
  coord_flip(xlim = c(1, 3),  ylim=c(0, 10), clip="off") +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  scale_y_continuous(breaks = c(0,2,4,6,8,10), minor_breaks = NULL) + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Economic left-right position", y = "") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 4, yend = 0.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 2.5, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 6, yend = 9.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 7.5, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 5.0, 
           label = "Belong to the people",
           size = 3, color = "black") +
  NULL

ggsave("./figures/FigureD2.png", width = 18, height = 9, units = "cm")

# Figure D3 (Margins People Interaction with LR Econ) ####

bind_rows(margins::margins(m2_imm3, variables = "populism_mean",
                           at = list(lrecon3 = c("Left", "Centre", "Right"))) %>%
            summary() %>% 
            data.frame() %>% 
            mutate(dv = "Citizens with migration background"),
          margins::margins(m2_wel3, variables = "populism_mean",
                           at = list(lrecon3 = c("Left", "Centre", "Right"))) %>%
            summary() %>%
            data.frame() %>% 
            mutate(dv = "Very wealthy citizens")) %>% 
  mutate(lrecon3 = factor(lrecon3,
                          levels = c("Left", "Centre", "Right"))) %>% 
  ggplot(., aes(x = lrecon3, y = AME, ymin = lower, ymax = upper)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_pointrange() +
  geom_linerange(aes(ymin = AME - 1.645 * SE, ymax = AME + 1.645 * SE), linewidth = 1) +
  theme_minimal() +
  facet_grid(~dv) + 
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Economic left-right position", y = "Marginal Effect Populism") +
  annotate("segment", 
           x = 0.8, xend = 0.8, y = -.15, yend = -.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = 0.6, y = -.4, 
           label = "Belong to the people: less",
           size = 3, color = "black", angle = 90)

ggsave("./figures/FigureD3.png", width = 18, height = 9, units = "cm")

# Figure D4 (Predictions People Interaction with Nativism)####

bind_rows(prediction::prediction(m2_imm3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, nativism = 2) %>% 
            mutate(dv = "Citizens with migration background"),
          prediction::prediction(m2_wel3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, nativism = 2) %>% 
            mutate(dv = "Very wealthy citizens")) %>% 
  mutate(populism_mean = factor(populism_mean,
                           levels = c(2,8),
                           labels = c("Low (2)", "High (8)"))) %>% 
  ggplot(., aes(x = nativism, y = Prediction, ymin = lower, ymax = upper, colour = factor(populism_mean), shape = factor(populism_mean))) +
  geom_pointrange(position = position_dodge(width = 0.25), size = .25) +
  geom_linerange(aes(ymin = Prediction - 1.645 * SE, ymax = Prediction + 1.645 * SE), linewidth = 1, position = position_dodge(width = 0.25)) +
  theme_minimal() +
  facet_grid(~dv) + 
  coord_flip(xlim = c(1, 3),  ylim=c(0, 10), clip="off") +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  scale_y_continuous(breaks = c(0,2,4,6,8,10), minor_breaks = NULL) + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Nativism", y = "") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 4, yend = 0.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 2.5, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 6, yend = 9.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 7.5, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 5.0, 
           label = "Belong to the people",
           size = 3, color = "black") +
  NULL

ggsave("./figures/FigureD4.png", width = 18, height = 9, units = "cm")

# Figure D5 (Margins People Interaction with Nativism) ####

bind_rows(margins::margins(m2_imm3, variables = "populism_mean",
                           at = list(nativism3 = c("Low", "Medium", "High"))) %>%
            summary() %>% 
            data.frame() %>% 
            mutate(dv = "Citizens with migration background"),
          margins::margins(m2_wel3, variables = "populism_mean",
                           at = list(nativism3 = c("Low", "Medium", "High"))) %>%
            summary() %>%
            data.frame() %>% 
            mutate(dv = "Very wealthy citizens")) %>% 
  ggplot(., aes(x = nativism3, y = AME, ymin = lower, ymax = upper)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_pointrange() +
  geom_linerange(aes(ymin = AME - 1.645 * SE, ymax = AME + 1.645 * SE), linewidth = 1) +
  theme_minimal() +
  facet_grid(~dv) + 
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Nativism", y = "Marginal Effect of Populism") +
  annotate("segment", 
           x = 0.8, xend = 0.8, y = -.15, yend = -.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = 0.6, y = -.4, 
           label = "Belong to the people: less",
           size = 3, color = "black", angle = 90)

ggsave("./figures/FigureD5.png", width = 18, height = 9, units = "cm")

# Figure D6 (Prediction People Interaction with LR Overall) ####

bind_rows(prediction::prediction(m1_pol3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lroverall = 2) %>% 
            mutate(dv = "The Elite (Political)"),
          prediction::prediction(m1_med3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lroverall = 2) %>% 
            mutate(dv = "The Elite (Media)"),
          prediction::prediction(m1_eco3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lroverall = 2) %>% 
            mutate(dv = "The Elite (Economic)"),
          prediction::prediction(m1_cul3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lroverall = 2) %>% 
            mutate(dv = "The Elite (Socio-cultural)")) %>% 
  
  mutate(populism_mean = factor(populism_mean,
                           levels = c(2,8),
                           labels = c("Low (2)", "High (8)"))) %>% 
  mutate(dv = factor(dv,
                     levels = c("The Elite (Political)", "The Elite (Media)", "The Elite (Economic)", "The Elite (Socio-cultural)"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  
  ggplot(., aes(x = lroverall, y = Prediction, ymin = lower, ymax = upper, colour = factor(populism_mean), shape = factor(populism_mean))) +
  geom_pointrange(position = position_dodge(width = 0.25), size = .25) +
  theme_minimal() +
  facet_wrap(~dv, scales = "free_y", nrow = 2, axes = "all_x") + 
  coord_flip(xlim = c(1, 3),  ylim=c(0, 10), clip="off") +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Left-Right Position", y = "") +
  annotate("segment", 
           x = -0.1, xend = -0.1, y = 4, yend = .5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0., y = 2, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.1, xend = -0.1, y = 6, yend = 9.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0., y = 8, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = 0.1, y = 5, 
           label = "Belong to the elite",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines")) +
  NULL
 
ggsave("./figures/FigureD6.png", width = 18, height = 18, units = "cm")

# Figure D7 (Margins Elite LR Overall) #####

bind_rows(margins::margins(m1_pol3, variables = "populism_mean",
                           at = list(lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%  
            data.frame() %>% 
            mutate(dv = "The Elite (Political)"),
          margins::margins(m1_med3, variables = "populism_mean",
                           at = list(lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Media)"),
          margins::margins(m1_eco3, variables = "populism_mean",
                           at = list(lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Economic)"),
          margins::margins(m1_cul3, variables = "populism_mean",
                           at = list(lroverall3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Socio-cultural)")) %>% 
  mutate(dv = factor(dv,
                     levels = c("The Elite (Political)", "The Elite (Media)", "The Elite (Economic)", "The Elite (Socio-cultural)"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  ggplot(., aes(x = lroverall3, y = AME, ymin = lower, ymax = upper)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_pointrange() +
  theme_minimal() +
  facet_wrap(~dv, nrow = 2) + 
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Left-Right Position", y = "Marginal Effect of Populism") +
  annotate("segment", 
           x = 0.8, xend = 0.8, y = .15, yend = .4,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = 0.6, y = .25, 
           label = "Belong to the elite: more",
           size = 3, color = "black", angle = 90) +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines")) +
  NULL

ggsave("./figures/FigureD7.png", width = 18, height = 18, units = "cm")

# Figure D8 (Predictions Elite Interaction with LR Econ) #####

bind_rows(prediction::prediction(m2_pol3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lrecon = 2) %>% 
            mutate(dv = "The Elite (Political)"),
          prediction::prediction(m2_med3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lrecon = 2) %>% 
            mutate(dv = "The Elite (Media)"),
          prediction::prediction(m2_eco3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lrecon = 2) %>% 
            mutate(dv = "The Elite (Economic)"),
          prediction::prediction(m2_cul3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, lrecon = 2) %>% 
            mutate(dv = "The Elite (Socio-cultural)")) %>% 
  mutate(populism_mean = factor(populism_mean,
                           levels = c(2,8),
                           labels = c("Low (2)", "High (8)")),
         dv = factor(dv,
                     levels = c("The Elite (Political)", "The Elite (Media)", "The Elite (Economic)", "The Elite (Socio-cultural)"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics")),
         lrecon = factor(lrecon,
                          levels = c("Left", "Centre", "Right"))) %>% 
  ggplot(., aes(x = lrecon, y = Prediction, ymin = lower, ymax = upper, colour = factor(populism_mean), shape = factor(populism_mean))) +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = Prediction - 1.645 * SE, ymax = Prediction + 1.645 * SE), linewidth = 1, position = position_dodge(width = 1)) +
  theme_minimal() +
  coord_flip(xlim = c(1, 3),  ylim=c(0, 10), clip="off") +
  facet_wrap(~dv, scales = "free_y", nrow = 2, axes = "all_x") + 
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Economic left-right position", y = "") +
  annotate("segment", 
           x = -0.1, xend = -0.1, y = 4, yend = .5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0., y = 2, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.1, xend = -0.1, y = 6, yend = 9.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0., y = 8, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = 0.1, y = 5, 
           label = "Belong to the elite",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines"))

ggsave("./figures/FigureD8.png", width = 18, height = 18, units = "cm")

# Figure D9 (Margins Elite Interaction with LR Econ) ####

bind_rows(margins::margins(m2_pol3, variables = "populism_mean",
                           at = list(lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%  
            data.frame() %>% 
            mutate(dv = "The Elite (Political)"),
          margins::margins(m2_med3, variables = "populism_mean",
                           at = list(lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Media)"),
          margins::margins(m2_eco3, variables = "populism_mean",
                           at = list(lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Economic)"),
          margins::margins(m2_cul3, variables = "populism_mean",
                           at = list(lrecon3 = c("Left", "Centre", "Right"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Socio-cultural)")) %>% 
  mutate(dv = factor(dv,
                     levels = c("The Elite (Political)", "The Elite (Media)", "The Elite (Economic)", "The Elite (Socio-cultural)"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics")),
         lrecon3 = factor(lrecon3,
                          levels = c("Left", "Centre", "Right"))) %>% 
  ggplot(., aes(x = lrecon3, y = AME, ymin = lower, ymax = upper)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_pointrange() +
  geom_linerange(aes(ymin = AME - 1.645 * SE, ymax = AME + 1.645 * SE), linewidth = 1) +
  theme_minimal() +
  facet_wrap(~dv, nrow = 2) +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Economic left-right position", y = "Marginal Effect of Populism") +
  annotate("segment", 
           x = 0.8, xend = 0.8, y = .15, yend = .3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = 0.6, y = .2, 
           label = "Belong to the elite: more",
           size = 3, color = "black", angle = 90) +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  NULL

ggsave("./figures/FigureD9.png", width = 18, height = 18, units = "cm")

# Figure D10 (Predictions Elite Interaction with Nativism) ####

bind_rows(prediction::prediction(m2_pol3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, nativism = 2) %>% 
            mutate(dv = "The Elite (Political)"),
          prediction::prediction(m2_med3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, nativism = 2) %>% 
            mutate(dv = "The Elite (Media)"),
          prediction::prediction(m2_eco3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, nativism = 2) %>% 
            mutate(dv = "The Elite (Economic)"),
          prediction::prediction(m2_cul3,
                                 variables = "populism_mean",
                                 at = list(populism_mean = c(2,8), 
                                           nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>% 
            rename(populism_mean = 1, nativism = 2) %>% 
            mutate(dv = "The Elite (Socio-cultural)")) %>% 
  mutate(populism_mean = factor(populism_mean,
                           levels = c(2,8),
                           labels = c("Low (2)", "High (8)")),
         dv = factor(dv,
                     levels = c("The Elite (Political)", "The Elite (Media)", "The Elite (Economic)", "The Elite (Socio-cultural)"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  ggplot(., aes(x = nativism, y = Prediction, ymin = lower, ymax = upper, colour = factor(populism_mean), shape = factor(populism_mean))) +
  geom_pointrange(position = position_dodge(width = 0.25), size = .25) +
  geom_linerange(aes(ymin = Prediction - 1.645 * SE, ymax = Prediction + 1.645 * SE), linewidth = 1, position = position_dodge(width = 0.25)) +
  theme_minimal() +
  facet_wrap(~dv, scales = "free_y", nrow = 2, axes = "all_x") + 
  coord_flip(xlim = c(1, 3),  ylim=c(0, 10), clip="off") +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Nativism", y = "") +
  annotate("segment", 
           x = -0.1, xend = -0.1, y = 4, yend = .5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0., y = 2, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.1, xend = -0.1, y = 6, yend = 9.5,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0., y = 8, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = 0.1, y = 5, 
           label = "Belong to the elite",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines"))

ggsave("./figures/FigureD10.png", width = 18, height = 18, units = "cm")

# Figure D11 (Margins Elite Interaction with Nativism) ####

bind_rows(margins::margins(m2_pol3, variables = "populism_mean",
                           at = list(nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>%  
            data.frame() %>% 
            mutate(dv = "The Elite (Political)"),
          margins::margins(m2_med3, variables = "populism_mean",
                           at = list(nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Media)"),
          margins::margins(m2_eco3, variables = "populism_mean",
                           at = list(nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Economic)"),
          margins::margins(m2_cul3, variables = "populism_mean",
                           at = list(nativism3 = c("Low", "Medium", "High"))) %>% 
            summary() %>%   
            data.frame() %>% 
            mutate(dv = "The Elite (Socio-cultural)")) %>% 
  mutate(dv = factor(dv,
                     levels = c("The Elite (Political)", "The Elite (Media)", "The Elite (Economic)", "The Elite (Socio-cultural)"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  ggplot(., aes(x = nativism3, y = AME, ymin = lower, ymax = upper)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_pointrange() +
  geom_linerange(aes(ymin = AME - 1.645 * SE, ymax = AME + 1.645 * SE), linewidth = 1) +
  theme_minimal() +
  facet_wrap(~dv, nrow = 2) +
  scale_colour_discrete("Populism") +
  scale_shape_discrete("Populism") + 
  theme(legend.position = "bottom",
        panel.border = element_rect(colour = "black", fill=NA, linewidth=1)) +
  labs(x = "Nativism", y = "Marginal Effect of Populism") + 
  annotate("segment", 
           x = 0.8, xend = 0.8, y = .15, yend = .4,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = 0.6, y = .25, 
           label = "Belong to the elite: more",
           size = 3, color = "black", angle = 90)

ggsave("./figures/FigureD11.png", width = 18, height = 18, units = "cm")

# Robustness checks ####

# Models: CFA ####

m1_imm <- lm(peopleimm ~ populism_cfa + lroverall + country, df)
m1_wel <- lm(peoplewealthy ~ populism_cfa + lroverall + country, df)
m2_imm <- lm(peopleimm ~ populism_cfa + lrecon + nativism + country, df)
m2_wel <- lm(peoplewealthy ~ populism_cfa + lrecon + nativism + country, df)

m1_pol <- lm(elitepol ~ populism_cfa + lroverall + country, df)
m1_med <- lm(elitemedia ~ populism_cfa + lroverall + country, df)
m1_eco <- lm(eliteecon ~ populism_cfa + lroverall + country, df)
m1_cul <- lm(elitecult ~ populism_cfa + lroverall + country, df)
m2_pol <- lm(elitepol ~ populism_cfa + lrecon + nativism + country, df)
m2_med <- lm(elitemedia ~ populism_cfa + lrecon + nativism + country, df)
m2_eco <- lm(eliteecon ~ populism_cfa + lrecon + nativism + country, df)
m2_cul <- lm(elitecult ~ populism_cfa + lrecon + nativism + country, df)


# Figure E1 (Coefficient Plots for Main models and elite) ####

data.frame(iv = rep(c("populism", "lroverall", "populism", "lrecon", "nativism"),2),
           dv = rep(c("peopleimm", "peoplewealthy "), each = 5),
           dim = rep(c("1D","1D", "2D","2D","2D"), 2),
           coef = c(m1_imm$coefficients[c("populism_cfa", "lroverall")],
                    m2_imm$coefficients[c("populism_cfa", "lrecon", "nativism")],
                    m1_wel$coefficients[c("populism_cfa", "lroverall")],
                    m2_wel$coefficients[c("populism_cfa", "lrecon", "nativism")]),
           se = c(sqrt(diag(vcov((m1_imm))))[c("populism_cfa", "lroverall")],
                  sqrt(diag(vcov((m2_imm))))[c("populism_cfa", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_wel))))[c("populism_cfa", "lroverall")],
                  sqrt(diag(vcov((m2_wel))))[c("populism_cfa", "lrecon", "nativism")])) %>% 
  mutate(lower95 = coef - 1.96*se,
         upper95 = coef + 1.96*se,
         lower90 = coef - 1.645*se,
         upper90 = coef + 1.645*se,
         iv = forcats::fct_rev(factor(iv, 
                                      levels = c("populism", "lroverall", "lrecon", "nativism"),
                                      labels = c("Populism", "Overall left-right", "Economic left-right", "Nativism"))),
         dim = factor(dim,
                      levels = c("1D", "2D"),
                      labels = c("One-Dimensional Model", "Two-Dimensional Model")),
         dv = factor(dv, 
                     levels = c("peopleimm", "peoplewealthy "),
                     labels = c("Citizens with migration background", "Very wealthy citizens"))) %>% 
  ggplot(., aes(x = iv, y = coef, ymin = lower95, ymax = upper95, colour = forcats::fct_rev(dim), shape = forcats::fct_rev(dim))) +
  geom_hline(yintercept = 0, lty ="dotted") +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = lower90, ymax = upper90), position = position_dodge(width = 1), linewidth = 0.75) +
  theme_minimal() +
  facet_grid(~dv) + 
  coord_flip(xlim = c(1, 4),  ylim=c(-0.8, 0.8), clip="off") +
  theme(legend.position = "bottom") +
  scale_colour_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  scale_shape_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  labs(x = "Predictor", y = "") +
  annotate("segment", 
           x = -0.45, xend = -0.45, y = -0.1, yend = -0.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.3, y = -0.3, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.45, xend = -0.45, y = 0.1, yend = 0.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.3, y = 0.3, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 0.0, 
           label = "Belong to the people",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureE1.png", width = 18, height = 9, units = "cm")

# Figure E2 (Coefficient Plots for Main models and elite) ####

data.frame(iv = rep(c("populism", "lroverall", "populism", "lrecon", "nativism"),2),
           dv = rep(c("elitepol", "elitemedia", "eliteecon", "elitecult"), each = 5),
           dim = rep(c("1D","1D", "2D","2D","2D"), 2),
           coef = c(m1_pol$coefficients[c("populism_cfa", "lroverall")],
                    m2_pol$coefficients[c("populism_cfa", "lrecon", "nativism")],
                    m1_med$coefficients[c("populism_cfa", "lroverall")],
                    m2_med$coefficients[c("populism_cfa", "lrecon", "nativism")],
                    m1_eco$coefficients[c("populism_cfa", "lroverall")],
                    m2_eco$coefficients[c("populism_cfa", "lrecon", "nativism")],
                    m1_cul$coefficients[c("populism_cfa", "lroverall")],
                    m2_cul$coefficients[c("populism_cfa", "lrecon", "nativism")]),
           se = c(sqrt(diag(vcov((m1_pol))))[c("populism_cfa", "lroverall")],
                  sqrt(diag(vcov((m2_pol))))[c("populism_cfa", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_med))))[c("populism_cfa", "lroverall")],
                  sqrt(diag(vcov((m2_med))))[c("populism_cfa", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_eco))))[c("populism_cfa", "lroverall")],
                  sqrt(diag(vcov((m2_eco))))[c("populism_cfa", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_cul))))[c("populism_cfa", "lroverall")],
                  sqrt(diag(vcov((m2_cul))))[c("populism_cfa", "lrecon", "nativism")])) %>% 
  mutate(lower95 = coef - 1.96*se,
         upper95 = coef + 1.96*se,
         lower90 = coef - 1.645*se,
         upper90 = coef + 1.645*se,
         iv = forcats::fct_rev(factor(iv, 
                                      levels = c("populism", "lroverall", "lrecon", "nativism"),
                                      labels = c("Populism", "Overall left-right", "Economic left-right", "Nativism"))),
         dim = factor(dim,
                      levels = c("1D", "2D"),
                      labels = c("One-Dimensional Model", "Two-Dimensional Model")),
         dv = factor(dv, 
                     levels = c("elitepol", "elitemedia", "eliteecon", "elitecult"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  ggplot(., aes(x = iv, y = coef, ymin = lower95, ymax = upper95, colour = forcats::fct_rev(dim), shape = forcats::fct_rev(dim))) +
  geom_hline(yintercept = 0, lty ="dotted") +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = lower90, ymax = upper90), position = position_dodge(width = 1), linewidth = .75) +
  theme_minimal() +
  facet_wrap(~dv, nrow = 2,axes = "all_x") + 
  coord_flip(xlim = c(1, 4),  ylim=c(-0.425, 0.425), clip="off") +
  theme(legend.position = "bottom") +
  scale_colour_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  scale_shape_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  labs(x = "Predictor", y = "") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = -0.1, yend = -0.3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = -0.15, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 0.1, yend = 0.3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 0.15, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 0.0, 
           label = "Belong to the elite",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines"))

ggsave("./figures/FigureE2.png", width = 18, height = 18, units = "cm")

# Table E1 ####

texreg::texreg(list(m1_imm, m1_wel),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_cfa" = "Populism (CFA)",
                                      "lroverall" = "Overall Left-Right Position",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. Populism is a factor score. All other variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableE1", 
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE1.tex")

# Table E2 ####

texreg::texreg(list(m2_imm, m2_wel),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_cfa" = "Populism (CFA)",
                                      "lrecon" = "Economic Left-Right Position",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. Populism is a factor score. All other variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               label = "tab:tableE2", 
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE2.tex")

# Table E3 ####

texreg::texreg(list(m1_pol, m1_med, m1_eco, m1_cul),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_cfa" = "Populism (CFA)",
                                      "lroverall" = "Overall Left-Right Position",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.9\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. Populism is a factor score. All other variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableE3",
               stars = c(0.1, 0.05, 0.01),
               scalebox = .8,
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE3.tex")

# Table E4 ####

texreg::texreg(list(m2_pol, m2_med, m2_eco, m2_cul),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_cfa" = "Populism (CFA)",
                                      "lrecon" = "Economic Left-Right",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.9\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. Populism is a factor score. All other variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableE4",
               stars = c(0.1, 0.05, 0.01),
               scalebox = .8,
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE4.tex")

# Alternative operationalisation of populism with AE and PC ####

df$populism_simple <- (df$antielitism + df$peoplecentrism)/2

m1_imm <- lm(peopleimm ~ populism_simple + lroverall + country, df)
m1_wel <- lm(peoplewealthy ~ populism_simple + lroverall + country, df)
m2_imm <- lm(peopleimm ~ populism_simple + lrecon + nativism + country, df)
m2_wel <- lm(peoplewealthy ~ populism_simple + lrecon + nativism + country, df)

m1_pol <- lm(elitepol ~ populism_simple + lroverall + country, df)
m1_med <- lm(elitemedia ~ populism_simple + lroverall + country, df)
m1_eco <- lm(eliteecon ~ populism_simple + lroverall + country, df)
m1_cul <- lm(elitecult ~ populism_simple + lroverall + country, df)
m2_pol <- lm(elitepol ~ populism_simple + lrecon + nativism + country, df)
m2_med <- lm(elitemedia ~ populism_simple + lrecon + nativism + country, df)
m2_eco <- lm(eliteecon ~ populism_simple + lrecon + nativism + country, df)
m2_cul <- lm(elitecult ~ populism_simple + lrecon + nativism + country, df)


# Figure E3 (Coefficient Plots for Main models and elite) ####

data.frame(iv = rep(c("populism", "lroverall", "populism", "lrecon", "nativism"),2),
           dv = rep(c("peopleimm", "peoplewealthy "), each = 5),
           dim = rep(c("1D","1D", "2D","2D","2D"), 2),
           coef = c(m1_imm$coefficients[c("populism_simple", "lroverall")],
                    m2_imm$coefficients[c("populism_simple", "lrecon", "nativism")],
                    m1_wel$coefficients[c("populism_simple", "lroverall")],
                    m2_wel$coefficients[c("populism_simple", "lrecon", "nativism")]),
           se = c(sqrt(diag(vcov((m1_imm))))[c("populism_simple", "lroverall")],
                  sqrt(diag(vcov((m2_imm))))[c("populism_simple", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_wel))))[c("populism_simple", "lroverall")],
                  sqrt(diag(vcov((m2_wel))))[c("populism_simple", "lrecon", "nativism")])) %>% 
  mutate(lower95 = coef - 1.96*se,
         upper95 = coef + 1.96*se,
         lower90 = coef - 1.645*se,
         upper90 = coef + 1.645*se,
         iv = forcats::fct_rev(factor(iv, 
                                      levels = c("populism", "lroverall", "lrecon", "nativism"),
                                      labels = c("Populism", "Overall left-right", "Economic left-right", "Nativism"))),
         dim = factor(dim,
                      levels = c("1D", "2D"),
                      labels = c("One-Dimensional Model", "Two-Dimensional Model")),
         dv = factor(dv, 
                     levels = c("peopleimm", "peoplewealthy "),
                     labels = c("Citizens with migration background", "Very wealthy citizens"))) %>% 
  ggplot(., aes(x = iv, y = coef, ymin = lower95, ymax = upper95, colour = forcats::fct_rev(dim), shape = forcats::fct_rev(dim))) +
  geom_hline(yintercept = 0, lty ="dotted") +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = lower90, ymax = upper90), position = position_dodge(width = 1), linewidth = 0.75) +
  theme_minimal() +
  facet_grid(~dv) + 
  coord_flip(xlim = c(1, 4),  ylim=c(-0.8, 0.8), clip="off") +
  theme(legend.position = "bottom") +
  scale_colour_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  scale_shape_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  labs(x = "Predictor", y = "") +
  annotate("segment", 
           x = -0.45, xend = -0.45, y = -0.1, yend = -0.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.3, y = -0.3, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.45, xend = -0.45, y = 0.1, yend = 0.6,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.3, y = 0.3, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 0.0, 
           label = "Belong to the people",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1))

ggsave("./figures/FigureE3.png", width = 18, height = 9, units = "cm")

# Figure E4 (Coefficient Plots for Main models and elite) ####

data.frame(iv = rep(c("populism", "lroverall", "populism", "lrecon", "nativism"),2),
           dv = rep(c("elitepol", "elitemedia", "eliteecon", "elitecult"), each = 5),
           dim = rep(c("1D","1D", "2D","2D","2D"), 2),
           coef = c(m1_pol$coefficients[c("populism_simple", "lroverall")],
                    m2_pol$coefficients[c("populism_simple", "lrecon", "nativism")],
                    m1_med$coefficients[c("populism_simple", "lroverall")],
                    m2_med$coefficients[c("populism_simple", "lrecon", "nativism")],
                    m1_eco$coefficients[c("populism_simple", "lroverall")],
                    m2_eco$coefficients[c("populism_simple", "lrecon", "nativism")],
                    m1_cul$coefficients[c("populism_simple", "lroverall")],
                    m2_cul$coefficients[c("populism_simple", "lrecon", "nativism")]),
           se = c(sqrt(diag(vcov((m1_pol))))[c("populism_simple", "lroverall")],
                  sqrt(diag(vcov((m2_pol))))[c("populism_simple", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_med))))[c("populism_simple", "lroverall")],
                  sqrt(diag(vcov((m2_med))))[c("populism_simple", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_eco))))[c("populism_simple", "lroverall")],
                  sqrt(diag(vcov((m2_eco))))[c("populism_simple", "lrecon", "nativism")],
                  sqrt(diag(vcov((m1_cul))))[c("populism_simple", "lroverall")],
                  sqrt(diag(vcov((m2_cul))))[c("populism_simple", "lrecon", "nativism")])) %>% 
  mutate(lower95 = coef - 1.96*se,
         upper95 = coef + 1.96*se,
         lower90 = coef - 1.645*se,
         upper90 = coef + 1.645*se,
         iv = forcats::fct_rev(factor(iv, 
                                      levels = c("populism", "lroverall", "lrecon", "nativism"),
                                      labels = c("Populism", "Overall left-right", "Economic left-right", "Nativism"))),
         dim = factor(dim,
                      levels = c("1D", "2D"),
                      labels = c("One-Dimensional Model", "Two-Dimensional Model")),
         dv = factor(dv, 
                     levels = c("elitepol", "elitemedia", "eliteecon", "elitecult"),
                     labels = c("Politicians", "Journalists", "CEOs", "Academics"))) %>% 
  ggplot(., aes(x = iv, y = coef, ymin = lower95, ymax = upper95, colour = forcats::fct_rev(dim), shape = forcats::fct_rev(dim))) +
  geom_hline(yintercept = 0, lty ="dotted") +
  geom_pointrange(position = position_dodge(width = 1), size = .25) +
  geom_linerange(aes(ymin = lower90, ymax = upper90), position = position_dodge(width = 1), linewidth = .75) +
  theme_minimal() +
  facet_wrap(~dv, nrow = 2,axes = "all_x") + 
  coord_flip(xlim = c(1, 4),  ylim=c(-0.425, 0.425), clip="off") +
  theme(legend.position = "bottom") +
  scale_colour_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  scale_shape_discrete("Model", breaks = c("One-Dimensional Model", "Two-Dimensional Model")) +
  labs(x = "Predictor", y = "") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = -0.1, yend = -0.3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = -0.15, 
           label = "less",
           size = 3, color = "black") +
  annotate("segment", 
           x = -0.35, xend = -0.35, y = 0.1, yend = 0.3,
           arrow=arrow(length=unit(0.1, "cm"), type = "closed")) +
  annotate("text", 
           x = -0.2, y = 0.15, 
           label = "more",
           size = 3, color = "black") +
  annotate("text", 
           x = -0.0, y = 0.0, 
           label = "Belong to the elite",
           size = 3, color = "black") +
  theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1),
        panel.spacing = unit(1, "lines"))

ggsave("./figures/FigureE4.png", width = 18, height = 18, units = "cm")


# Table E5 ####

texreg::texreg(list(m1_imm, m1_wel),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_simple" = "Populism (Simplified)",
                                      "lroverall" = "Overall Left-Right Position",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableE5", 
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE5.tex")

# Table E6 ####

texreg::texreg(list(m2_imm, m2_wel),
               custom.model.names = c("Citizens with migration background", "Very wealthy citizens"),
               custom.coef.map = list("populism_simple" = "Populism (Simplified)",
                                      "lrecon" = "Economic Left-Right Position",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the people",
               caption.above = T,
               custom.note = "\\parbox{0.8\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               label = "tab:tableE6", 
               stars = c(0.1, 0.05, 0.01),
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE6.tex")

# Table E7 ####

texreg::texreg(list(m1_pol, m1_med, m1_eco, m1_cul),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_simple" = "Populism (Simplified)",
                                      "lroverall" = "Overall Left-Right Position",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.9\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableE7",
               stars = c(0.1, 0.05, 0.01),
               scalebox = .8,
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE7.tex")

# Table E8 ####

texreg::texreg(list(m2_pol, m2_med, m2_eco, m2_cul),
               custom.model.names = c("Politicians", "Journalists", "CEOs", "Academics"),
               custom.coef.map = list("populism_simple" = "Populism (Simplified)",
                                      "lrecon" = "Economic Left-Right",
                                      "nativism" = "Nativism",
                                      "(Intercept)" = "Intercept",
                                      "countryBelgium" = "CFE: BEL",
                                      "countryBulgaria" = "CFE: BGR",
                                      "countryCroatia" = "CFE: HRV",
                                      "countryCyprus" = "CFE: CYP",
                                      "countryCzech Republic" = "CFE: CZE",
                                      "countryDenmark" = "CFE: DNK",
                                      "countryEstonia" = "CFE: EST",
                                      "countryFinland" = "CFE: FIN",
                                      "countryFrance" = "CFE: FRA",
                                      "countryGermany" = "CFE: DEU",
                                      "countryGreece" = "CFE: GRC",
                                      "countryHungary" = "CFE: HUN",
                                      "countryIceland" = "CFE: ISL",
                                      "countryIreland" = "CFE: IRL",
                                      "countryItaly" = "CFE: ITA",
                                      "countryLatvia" = "CFE: LVA",
                                      "countryLithuania" = "CFE: LTU",
                                      "countryLuxembourg" = "CFE: LUX",
                                      "countryMalta" = "CFE: MLT",
                                      "countryNetherlands" = "CFE: NLD",
                                      "countryNorway" = "CFE: NOR",
                                      "countryPoland" = "CFE: POL",
                                      "countryPortugal" = "CFE: PRT",
                                      "countryRomania" = "CFE: ROU",
                                      "countrySlovakia" = "CFE: SVK",
                                      "countrySlovenia" = "CFE: SLV",
                                      "countrySpain" = "CFE: ESP",
                                      "countrySweden" = "CFE: SWE",
                                      "countrySwitzerland" = "CFE: CHE",
                                      "countryUnited Kingdom" = "CFE: GBR"),
               single.row = T,
               caption = "Populism, ideology and the elite",
               caption.above = T,
               custom.note = "\\parbox{0.9\\linewidth}{%stars. Entries are unstandardised regression coefficients from a OLS regression. All variables operate on a scale form 0 to 10. Reference for country-fixed effects is Austria.}",
               float = "htb", 
               label = "tab:tableE8",
               stars = c(0.1, 0.05, 0.01),
               scalebox = .8,
               dcolumn = T,
               use.packages = F,
               file = "./tables/TableE8.tex")

# Descriptive information on experts ####

readRDS(file = "data_expert.RDS") %>% 
  select(response_id, country_short) %>% 
  distinct() %>% 
  group_by(country_short) %>% 
  summarise(n = n()) %>% 
  ungroup() %>% 
  summarise(mean(n),
            median(n))

readRDS(file = "data_expert.RDS") %>% 
  select(response_id, country_short) %>% 
  distinct() %>% 
  group_by(country_short) %>% 
  summarise(n()) %>% 
  print(n = 32)
